//package com.kira.scaffoldmvc.Trace;
//
//import cn.hutool.core.util.IdUtil;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.slf4j.MDC;
//import org.springframework.stereotype.Component;
//
//@Aspect
//@Component
//public class ControllerLogAspect {
//
//    public static final String TRACE_ID = "traceId";
//    private static final Logger logger = LoggerFactory.getLogger(ControllerLogAspect.class);
//
//    // 定义切入点，匹配带有 @Controller、@RestController 或 @Service 注解的类中的所有方法
//    @Pointcut("@within(org.springframework.stereotype.Controller) || @within(org.springframework.web.bind.annotation.RestController) || @within(org.springframework.stereotype.Service)")
//    public void controllerAndServiceMethods() {
//    }
//
//    @Around("controllerAndServiceMethods()")
//    public Object around(ProceedingJoinPoint point) throws Throwable {
//        try {
//            String traceId = IdUtil.objectId();
//            String fullTraceId = "追踪ID:" + traceId;
//            MDC.put(TRACE_ID, fullTraceId);
//            logger.info("Generated traceId: {}", fullTraceId); // 调试日志
//            return point.proceed();
//        } finally {
//            MDC.remove(TRACE_ID);
//        }
//    }
//}